
package dhee.wtqshopproject.dao;

import dhee.wtqshopproject.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
//插入 int返回用来判断插入成功
    @Insert("INSERT INTO category (category_name, is_use) " +
            "VALUES (#{categoryName}, #{isUse})")
    @Options(useGeneratedKeys = true, keyProperty = "categoryId")
    int insert(Category category);
    //删除 同理
    @Delete("DELETE FROM category WHERE category_id = #{categoryId}")
    int deleteById(Integer categoryId);
  //更新 同理
    @Update("UPDATE category SET " +
            "category_name = #{categoryName}, " +
            "is_use = #{isUse} " +
            "WHERE category_id = #{categoryId}")
    int update(Category category);
   //查询
    @Select("SELECT * FROM category WHERE category_id = #{categoryId}")
    Category selectById(Integer categoryId);
//列表展示部分
    @Select("SELECT * FROM category")
    List<Category> selectAll();
    //停用方法
    @Update("UPDATE category SET is_use = #{isUse} WHERE category_id = #{categoryId}")
    int updateStatus(@Param("categoryId") Integer categoryId,
                     @Param("isUse") Integer isUse);
}